package rabbit.proxy;

import rabbit.util.TrafficLogger;
import rabbit.util.SimpleTrafficLogger;

/** A class to track of multiple network flows.
 *
 * @author <a href="mailto:robo@khelekore.org">Robert Olofsson</a>
 */
public class TrafficLoggerHandler {
    // normal client traffic
    private final TrafficLogger client;

    // normal web connections (real servers or proxy up the chain).
    private final TrafficLogger network;

    // cached resources
    private final TrafficLogger cache;

    // internally generated by this proxy
    private final TrafficLogger proxy;

    /** Create a new TrafficLoggerHandler
     */
    public TrafficLoggerHandler () {
	client = new SimpleTrafficLogger ();
	network = new SimpleTrafficLogger ();
	cache = new SimpleTrafficLogger ();
	proxy = new SimpleTrafficLogger ();
    }

    /** Get the TrafficLogger with the traffic statistics for client data
     * @return the TrafficLogger for the client data
     */
    public TrafficLogger getClient () {
	return client;
    }

    /** Get the TrafficLogger with the traffic statistics for network data
     * @return the TrafficLogger for network data
     */
    public TrafficLogger getNetwork () {
	return network;
    }

    /** Get the TrafficLogger with the traffic statistics for cache data
     * @return the TrafficLogger for cache data
     */
    public TrafficLogger getCache () {
	return cache;
    }

    /** Get the TrafficLogger with the traffic statistics for data to
     *  and from this proxy
     * @return the TrafficLogger for the proxy data
     */
    public TrafficLogger getProxy () {
	return proxy;
    }

    /** Add our statistics to the given other TrafficLoggerHandler.
     * @param other the TrafficLoggerHandler to update
     */
    public void addTo (TrafficLoggerHandler other) {
	client.addTo (other.client);
	network.addTo (other.network);
	cache.addTo (other.cache);
	proxy.addTo (other.proxy);
    }

    /** Zero out all statistics in this TrafficLoggerHandler.
     */
    public void clear () {
	client.clear ();
	network.clear ();
	cache.clear ();
	proxy.clear ();
    }
}
